﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class ResourcePool
{
    private List<Resource> resourcePool;

    public ResourcePool(List<Resource> resources)
    {
        this.resourcePool = new List<Resource>();
        if (resources != null)
        {
            foreach (Resource res in resources)
            {
                this.resourcePool.Add(new Resource(res.Data));
            }
        }
    }

    public ResourcePool()
        : this(null)
    { }

    public Resource GetResource()
    {
        foreach (Resource res in this.resourcePool)
        {
            if (res.Available)
            {
                res.Use();
                return res;
            }
        }
        throw new ResourceNotAvailableException("Resource not available");
    }
}

